// MyFamily - XML based genealogy program.
// Copyright (C) 2006  Doug Swisher
// See the file COPYING.txt for license details.

using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;

using DataModel;
using WebLib;


namespace CommonGui
{
    public partial class LoadResultsDialog2 : Form
    {
        private LoadResults loadResults;
        private WebSiteResults webSiteResults;

        public LoadResultsDialog2(LoadResults loadResults, WebSiteResults webSiteResults)
        {
            this.loadResults = loadResults;
            this.webSiteResults = webSiteResults;

            InitializeComponent();
        }

        private void LoadResultsDialog_Load(object sender, EventArgs e)
        {
            this.IndividualCountTextBox.Text = this.loadResults.IndividualCount.ToString();
            this.PersonaCountTextBox.Text = this.loadResults.PersonaCount.ToString();
            this.ExtractCountTextBox.Text = this.loadResults.ExtractCount.ToString();
            this.SourceCountTextBox.Text = this.loadResults.SourceCount.ToString();
            this.OutputDirectoryTextBox.Text = this.webSiteResults.OutputDirectoryInfo.FullName;

            this.WarningCountTextBox.Text = (loadResults.WarningCount + webSiteResults.WarningCount).ToString();

            foreach (string message in webSiteResults.Messages)
            {
                this.MessagesTextBox.AppendText(message + "\r\n");
            }
        
            foreach (string message in loadResults.Messages)
            {
                this.MessagesTextBox.AppendText(message + "\r\n");
            }
        }

        private void MyOkButton_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                string url = Path.Combine(this.webSiteResults.OutputDirectoryInfo.FullName, "default.htm");

                Process.Start(url);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.ToString(), "Web browser launch threw an exception");
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void GoToWebSiteButton_Click(object sender, EventArgs e)
        {
            Process.Start(this.OutputDirectoryTextBox.Text);
        }
    }
}